package com.dds.web.controller.shop;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dds.common.annotation.Log;
import com.dds.common.core.controller.BaseController;
import com.dds.common.core.domain.AjaxResult;
import com.dds.common.enums.BusinessType;
import com.dds.system.domain.union.UnionShopIndex;
import com.dds.system.service.union.IUnionShopIndexService;
import com.dds.common.utils.poi.ExcelUtil;
import com.dds.common.core.page.TableDataInfo;

/**
 * 联盟商家Controller
 * 
 * @author gaolianjie
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/union/shop")
public class UnionShopIndexController extends BaseController
{
    @Autowired
    private IUnionShopIndexService unionShopIndexService;

    /**
     * 查询联盟商家列表
     */
    @PreAuthorize("@ss.hasPermi('union:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(UnionShopIndex unionShopIndex)
    {
        startPage();
        List<UnionShopIndex> list = unionShopIndexService.selectUnionShopIndexList(unionShopIndex);
        return getDataTable(list);
    }

    /**
     * 导出联盟商家列表
     */
    @PreAuthorize("@ss.hasPermi('union:shop:export')")
    @Log(title = "联盟商家", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UnionShopIndex unionShopIndex)
    {
        List<UnionShopIndex> list = unionShopIndexService.selectUnionShopIndexList(unionShopIndex);
        ExcelUtil<UnionShopIndex> util = new ExcelUtil<UnionShopIndex>(UnionShopIndex.class);
        return util.exportExcel(list, "shop");
    }

    /**
     * 获取联盟商家详细信息
     */
    @PreAuthorize("@ss.hasPermi('union:shop:query')")
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable("shopId") String shopId)
    {
        return AjaxResult.success(unionShopIndexService.selectUnionShopIndexById(shopId));
    }

    /**
     * 新增联盟商家
     */
    @PreAuthorize("@ss.hasPermi('union:shop:add')")
    @Log(title = "联盟商家", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UnionShopIndex unionShopIndex)
    {
        return toAjax(unionShopIndexService.insertUnionShopIndex(unionShopIndex));
    }

    /**
     * 修改联盟商家
     */
    @PreAuthorize("@ss.hasPermi('union:shop:edit')")
    @Log(title = "联盟商家", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UnionShopIndex unionShopIndex)
    {
        return toAjax(unionShopIndexService.updateUnionShopIndex(unionShopIndex));
    }

    /**
     * 删除联盟商家
     */
    @PreAuthorize("@ss.hasPermi('union:shop:remove')")
    @Log(title = "联盟商家", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shopIds}")
    public AjaxResult remove(@PathVariable String[] shopIds)
    {
        return toAjax(unionShopIndexService.deleteUnionShopIndexByIds(shopIds));
    }
}
